import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

import NProgress from 'nprogress'

import DefaultLayout from '@/layouts/DefaultLayout'

const routes = [
  // 框架内的路由
  {
    path: '/',
    name: 'Layout',
    component: DefaultLayout,
    children: [
      {
        path: '',
        name: 'Home',
        meta: { title: '首页' },
        component: () => import('../views/Home.vue')
      },
      {
        path: 'about',
        name: 'About',
        meta: { title: '关于页面' },
        component: () => import('../views/About.vue')
      },
      {
        path: 'setting',
        name: 'Setting',
        component: () => import('../views/Setting.vue')
      },
      {
        path: 'system',
        name: 'System',
        component: () => import('../views/System.vue'),
        children: [
          // /system/user
          {
            path: 'user',
            name: 'SystemUser',
            component: () => import('../views/SystemUser.vue'),
          },
          // /system/role
          {
            path: 'role',
            name: 'SystemRole',
            component: () => import('../views/SystemRole.vue'),
          }
        ]
      },
      {
        path: 'basic',
        name: 'Basic',
        meta: { title: '基础' },
        component: () => import('../views/Basic.vue'),
        children: [
          // /basic/icon
          {
            path: 'icon',
            name: 'BasicIcon',
            component: () => import('../views/BasicIcon.vue'),
          },
          // /basic/botton
          {
            path: 'botton',
            name: 'BasicBotton',
            component: () => import('../views/BasicBotton.vue'),
          },

        ]

      },
      {
        path: 'radio',
        name: 'Radio',
        component: () => import('../views/Radio.vue')
      },
      {
        path: 'input',
        name: 'Input',
        component: () => import('../views/Input.vue')
      },
      {
        path: 'select',
        name: 'Select',
        component: () => import('../views/Select.vue')
      },
      {
        path: 'datePicker',
        name: 'DatePicker',
        component: () => import('../views/DatePicker.vue')
      },
      {
        path: 'form',
        name: 'Form',
        component: () => import('../views/Form.vue')
      },
      {
        path: 'table',
        name: 'Table',
        component: () => import('../views/Table.vue')
      },
      {
        path: 'pagination',
        name: 'Pagination',
        component: () => import('../views/Pagination.vue')
      },
      {
        path: 'message',
        name: 'Message',
        component: () => import('../views/Message.vue')
      },
      {
        path: 'messagebox',
        name: 'MessageBox',
        component: () => import('../views/MessageBox.vue')
      },
      {
        path: 'tabs',
        name: 'Tabs',
        component: () => import('../views/Tabs.vue')
      },
      {
        path: 'dialog',
        name: 'DiaLog',
        component: () => import('../views/DiaLog.vue')
      },
      {
        path: 'card',
        name: 'Card',
        component: () => import('../views/Card.vue')
      },
      {
        path: 'carousel',
        name: 'Carousel',
        component: () => import('../views/Carousel.vue')
      },
      {
        path: 'image',
        name: 'Image',
        component: () => import('../views/Image.vue')
      },
      {
        path: 'drawer',
        name: 'Drawer',
        component: () => import('../views/Drawer.vue')
      },
      





    ]
  },

  // 框架外的路由
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '*',
    name: 'NotFound',
    component: () => import("@/views/404.vue")
  },
]

const router = new VueRouter({
  routes
})

// 设置路由：前置守卫
// router.beforeEach((to, from, next) => {
//   console.log("要前往的页面", to)
//   console.log("原来的页面", from)

//   NProgress.start()

//   const { path, meta: { title } } = to

//   if (title) {
//     document.title = title
//   } else {
//     document.title = "没有标题"
//   }

//   if (path === '/setting') {
//     console.log("被拦截了")
//     next("/no-found")
//   } else {
//     next()
//   }

//   next()
// })

router.afterEach(() => {
  NProgress.done()
})

export default router
